#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int sz[N], fa[N], son[N], dep[N];
void dfs(int u, int fu) {
  dep[u] = dep[fu] + 1;
  fa[u] = fu;
  sz[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
int top[N], c[N], pos[N], num;
void dfs2(int u, int fu, int t) {
  top[u] = t;
  pos[u] = ++num;
  c[num] = a[u];
  if (!son[u]) return;
  dfs2(son[u], u, t);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == son[u] || v == fu) continue;
    dfs2(v, u, v);
  }
}
struct Node {
  int cnt, cl, cr, tag;
} tr[N << 2];
Node merge(Node x, Node y) {
  if (!x.cnt) return y;
  if (!y.cnt) return x;
  Node res{x.cnt + y.cnt, x.cl, y.cr, 0};
  if (x.cr == y.cl) res.cnt--;
  return res;
}
void pushup(int p) { tr[p] = merge(tr[p << 1], tr[p << 1 | 1]); }
void build(int p, int l, int r) {
  if (l == r) {
    tr[p] = Node{1, c[l], c[l], 0};
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void addtag(int x, int p, int l, int r) {
  tr[p].tag = x;
  tr[p].cnt = 1;
  tr[p].cl = tr[p].cr = x;
}
void pushdown(int p, int l, int r) {
  if (tr[p].tag) {
    int mid = (l + r) >> 1;
    addtag(tr[p].tag, p << 1, l, mid);
    addtag(tr[p].tag, p << 1 | 1, mid + 1, r);
    tr[p].tag = 0;
  }
}
void update(int L, int R, int x, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(x, p, l, r);
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, x, p << 1, l, mid);
  if (R > mid) update(L, R, x, p << 1 | 1, mid + 1, r);
  pushup(p);
}
Node query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return tr[p];
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid && R > mid) {
    Node x = query(L, R, p << 1, l, mid);
    Node y = query(L, R, p << 1 | 1, mid + 1, r);
    return merge(x, y);
  } else if (L <= mid)
    return query(L, R, p << 1, l, mid);
  else
    return query(L, R, p << 1 | 1, mid + 1, r);
}
void update(int u, int v, int c) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    update(pos[top[u]], pos[u], c, 1, 1, n);
    u = fa[top[u]];
  }
  if (dep[u] > dep[v]) swap(u, v);
  update(pos[u], pos[v], c, 1, 1, n);
}
int query(int u, int v) {
  Node x{0, 0, 0, 0}, y{0, 0, 0, 0};
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) {
      y = merge(query(pos[top[v]], pos[v], 1, 1, n), y);
      v = fa[top[v]];
    } else {
      x = merge(query(pos[top[u]], pos[u], 1, 1, n), x);
      u = fa[top[u]];
    }
  }
  if (dep[u] < dep[v]) {
    y = merge(query(pos[u], pos[v], 1, 1, n), y);
    return x.cnt + y.cnt - (x.cl == y.cl ? 1 : 0);
  } else {
    x = merge(query(pos[v], pos[u], 1, 1, n), x);
    return x.cnt + y.cnt - (x.cl == y.cl ? 1 : 0);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  dfs(1, 0);
  dfs2(1, 0, 1);
  build(1, 1, n);
  while (m--) {
    char op;
    int x, y, z;
    cin >> op >> x >> y;
    if (op == 'C') {
      cin >> z;
      update(x, y, z);
    } else {
      cout << query(x, y) << endl;
    }
  }
  return 0;
}